package cn.iocoder.yudao.module.fm.controller.admin.tunneldefaultdata;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.fm.controller.admin.tunneldefaultdata.vo.*;
import cn.iocoder.yudao.module.fm.dal.dataobject.tunneldefaultdata.TunnelDefaultDataDO;
import cn.iocoder.yudao.module.fm.convert.tunneldefaultdata.TunnelDefaultDataConvert;
import cn.iocoder.yudao.module.fm.service.tunneldefaultdata.TunnelDefaultDataService;

@Tag(name = "管理后台 - 隧道 默认数据")
@RestController
@RequestMapping("/fm/tunnel-default-data")
@Validated
public class TunnelDefaultDataController {

    @Resource
    private TunnelDefaultDataService tunnelDefaultDataService;

    @PostMapping("/create")
    @Operation(summary = "创建隧道 默认数据")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:create')")
    public CommonResult<Long> createTunnelDefaultData(@Valid @RequestBody TunnelDefaultDataCreateReqVO createReqVO) {
        return success(tunnelDefaultDataService.createTunnelDefaultData(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新隧道 默认数据")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:update')")
    public CommonResult<Boolean> updateTunnelDefaultData(@Valid @RequestBody TunnelDefaultDataUpdateReqVO updateReqVO) {
        tunnelDefaultDataService.updateTunnelDefaultData(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除隧道 默认数据")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:delete')")
    public CommonResult<Boolean> deleteTunnelDefaultData(@RequestParam("id") Long id) {
        tunnelDefaultDataService.deleteTunnelDefaultData(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得隧道 默认数据")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:query')")
    public CommonResult<TunnelDefaultDataRespVO> getTunnelDefaultData(@RequestParam("id") Long id) {
        TunnelDefaultDataDO tunnelDefaultData = tunnelDefaultDataService.getTunnelDefaultData(id);
        return success(TunnelDefaultDataConvert.INSTANCE.convert(tunnelDefaultData));
    }

    @GetMapping("/list")
    @Operation(summary = "获得隧道 默认数据列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:query')")
    public CommonResult<List<TunnelDefaultDataRespVO>> getTunnelDefaultDataList(@RequestParam("ids") Collection<Long> ids) {
        List<TunnelDefaultDataDO> list = tunnelDefaultDataService.getTunnelDefaultDataList(ids);
        return success(TunnelDefaultDataConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得隧道 默认数据分页")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:query')")
    public CommonResult<PageResult<TunnelDefaultDataRespVO>> getTunnelDefaultDataPage(@Valid TunnelDefaultDataPageReqVO pageVO) {
        PageResult<TunnelDefaultDataDO> pageResult = tunnelDefaultDataService.getTunnelDefaultDataPage(pageVO);
        return success(TunnelDefaultDataConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出隧道 默认数据 Excel")
//    @PreAuthorize("@ss.hasPermission('fm:tunnel-default-data:export')")
    @OperateLog(type = EXPORT)
    public void exportTunnelDefaultDataExcel(@Valid TunnelDefaultDataExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<TunnelDefaultDataDO> list = tunnelDefaultDataService.getTunnelDefaultDataList(exportReqVO);
        // 导出 Excel
        List<TunnelDefaultDataExcelVO> datas = TunnelDefaultDataConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "隧道 默认数据.xls", "数据", TunnelDefaultDataExcelVO.class, datas);
    }

}
